package kr.hkit.powerjava.chapter26; //PDF 134p

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Scanner;

import kr.hkit.powerjava.chapter26.common.ConnectionFactory;
import kr.hkit.powerjava.chapter26.common.DbUtil;
import kr.hkit.powerjava.chapter26.dao.DepartmentDAO;
import kr.hkit.powerjava.chapter26.dao.EmployeeDAO;
import kr.hkit.powerjava.chapter26.dto.Department;
import kr.hkit.powerjava.chapter26.dto.Employee;
import kr.hkit.powerjava.chapter26.service.AbsService;
import kr.hkit.powerjava.chapter26.service.DepartmentService;
import kr.hkit.powerjava.chapter26.service.EmployeeService;

public class TestMain {
	public static void main(String[] args) {
	
		
		Scanner sc = new Scanner(System.in);
		Connection connection = ConnectionFactory.getConnection(); 
		
		int res = 0;
		do{
			System.out.println("1.Department 2.Employee");
			res = sc.nextInt();
			switch (res) {
				case 1 :
					AbsService<Department> deptSvc = new DepartmentService(sc, connection);
					deptSvc.prnMenu();
					break;
				case 2 :
					AbsService<Employee> empSvc = new EmployeeService(sc, connection);
					empSvc.prnMenu();
				default :
					res = 3;
			}
		} while (res < 3);
		
		DbUtil.close(connection);
	
	

		
		/*
		//Department 
		AbsService<Department> deptSvc = new DepartmentService(sc, connection);
		deptSvc.prnMenu();
		*/
		
		/*
		//Employee
		AbsService<Employee> empSvc = new EmployeeService(sc, connection);
		empSvc.prnMenu();
		*/
		
		
		/*
		//sql맞는지 테스트용!!
		Connection connection = ConnectionFactory.getConnection(); 
		
		EmployeeDAO dao = new EmployeeDAO(connection);
		
		try {
			dao.insertItem(new Employee(5000, "추지영", "주임", 3011, 1500000, 3));
			System.out.println("삽입성공");
		} catch (SQLException e) {
			System.err.println(e.getMessage()+":" + e.getErrorCode()); 
		}
		
		*/
	
		
		//--------------------------------------------------------
		
		/*DepartmentDAO dao = new DepartmentDAO(); //던져준거 여기서 처리
		
		try { //리스트 보기 
			ArrayList<Department> list = dao.listItems();
			for (Department d : list) {
				System.out.println(d);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}*/
		
		
//		Department d = new Department(6, "마케팅", 8);
		
	/*	try {
			dao.insertItem(d); //계속 쓸거라서 빼둠
			System.out.println("삽입 성공" + d);
		} catch (SQLException e) {
			System.err.println(e.getMessage()+":" + e.getErrorCode()); 
		} //예외처리 했기때문에 밑에꺼 수행됨
		*/
		
	/*	try {
			d.setDeptName("교육");
//			d.setFloor(9);
			dao.updateItemByNo(d);
			System.out.println("갱신 성공" + d);
		} catch (SQLException e) {
			System.err.println(e.getMessage()+":" + e.getErrorCode()); 
			}*/
		
		
		/*try {
			dao.deleteItemByNo(new Department(6));
			System.out.println("삭제 성공" + d);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		*/
		
		/*
		
		Connection con = ConnectionFactory.getConnection();
		System.out.println(con);
		//mysql_lib없으면 에러뜸
*/		

		/*
		String driver = "com.mysql.jdbc.Driver"; //mysql.lib에 driver클래스 쓰겠다
		String url = "jdbc:mysql://localhost:3306/mysql_study"; //이건 약속임
		String user = "root";
		String password = "1111";
		DBProperties.savePropertis("dbcon.xml", driver,url,user,password);
	
		
		//properties는 속성, 설정값 저장할때 씁니다. 
		//제대로 읽어지는지 테스트
		Properties prop = DBProperties.loadPropertis("dbcon.xml");
		
		DBProperties.prnProperties(prop);*/
		

		
	}
}

